package com.inwavetech.os.sync.jsonparser;

import com.inwavetech.os.entity.enummap.EnumMap;

/**
 * Created by jgskin on 3/6/14.
 */
public class EnumCleaner implements JsonCleaner {
    private final EnumMap map;
    private boolean required;

    public EnumCleaner(EnumMap map, boolean required) {
        this.map = map;
        this.required = required;
    }

    @Override
    public Object validateAndClean(String receivedValue) {
        if (receivedValue.isEmpty() && required == false) {
            return null;
        }

        try {
            return map.getEnum(receivedValue);
        } catch (IndexOutOfBoundsException e) {
            return false;
        }
    }
}
